<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="template.xhtml">
	<ui:define name="content">
		<h:form id="form01">
			<p:growl id="messages" />
			<p:panel header="Patient List" style="text-align:center">

				<div style="float: left">
					<p:commandButton id="addNewBtn" ajax="true"
						value="#{dictionaryControler.dictionary['Add']} #{dictionaryControler.dictionary['Patient']}"
						actionListener="#{patientListControler.startAddPatient}"
						icon="ui-icon-plus" update=":form04:detailDialog" />
				</div>
				<br />
				<br />
				<br />
				<br />
				<p:dataTable id="patientTable" widgetVar="widgetVar_w"
					resizableColumns="true" style="margin-bottom:20px"
					rendered="#{mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('patient')}"
					value="#{patientListControler.patientList}" var="patient" rows="15"
					paginator="true" paginatorAlwaysVisible="true"
					filteredValue="#{patientListControler.filteredTerms}"
					paginatorPosition="bottom" first="#{patientListControler.first}"
					paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink}">
					<p:column style="width:10%" filterBy="#{patient.seq}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Seq']}">
						<h:outputText value="#{patient.seq}" />
					</p:column>
					<p:column style="width:10%" filterBy="#{patient.name}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{patient.name}" />
					</p:column>
					<p:column style="width:10%" filterMatchMode="exact"
						filterBy="#{patient.gender}"
						headerText="#{dictionaryControler.dictionary['Gender']}">
						<f:facet name="filter">
							<p:selectOneMenu onchange="PF('widgetVar_w').filter()">
								<f:selectItem itemLabel="Select One" itemValue="#{null}"
									noSelectionOption="true" />
								<f:selectItems value="#{genderListControler.genderList}"
									var="gender" itemLabel="#{gender.label}"
									itemValue="#{gender.value}" />
							</p:selectOneMenu>
						</f:facet>
						<h:outputText
							value="#{dictionaryControler.dictionary[patient.genderName]}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Age']}">
						<h:outputText value="#{patient.age}" />
					</p:column>
					<p:column style="width:10%" filterBy="#{patient.phoneNumber}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['PhoneNumber']}">
						<h:outputText value="#{patient.phoneNumber}" />
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Edit']}">
						<p:commandButton id="editButton" update=":form04:detailDialog_1"
							action="#{patientListControler.startEditPatient}"
							icon="ui-icon-pencil">
							<f:setPropertyActionListener value="#{patient}"
								target="#{patientListControler.selectedPatient}" />
						</p:commandButton>
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Register']}">
						<p:commandButton id="registerButton"
							update=":form04:registerDialog_id"
							action="#{registerControler.startRegister}" icon="ui-icon-pencil">
							<f:setPropertyActionListener value="#{patient}"
								target="#{registerControler.selectedPatient}" />
						</p:commandButton>
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Delete']}">
						<p:commandButton id="deleteButton" ajax="true"
							oncomplete="PF('widgetVar_w').clearFilters();"
							action="#{patientListControler.deletePatient}"
							update=":form01:patientTable" icon="ui-icon-close"
							style="margin-right:5px">
							<f:setPropertyActionListener value="#{patient}"
								target="#{patientListControler.selectedPatient}" />
							<p:confirm
								header="#{dictionaryControler.dictionary['Confirmation']}"
								message="#{dictionaryControler.dictionary['Are you sure']}?"
								icon="ui-icon-alert" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
			<h:outputText value="Access Denied, please contact the administrator"
				rendered="#{!(mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('patient'))}"
				style="width:100%; height:50%; text-align:center; font-size:150% !important;position:absolute; margin-left:0; margin-right:0; margin-top:0;margin-bottom:0" />
		</h:form>
	</ui:define>

	<ui:define name="dialog">
		<h:form id="form04">
			<p:dialog id="detailDialog" widgetVar="detailDialog_w" modal="true"
				showEffect="fade" resizable="false" draggable="true"
				closable="false" visible="#{patientListControler.addMode}"
				header="#{dictionaryControler.dictionary['Add']} #{dictionaryControler.dictionary['Patient']}">
				<p:focus context="detailDialog" for="addBtn" />
				<p:panelGrid columns="2">
					<h:outputText value="#{dictionaryControler.dictionary['Name']}" />
					<p:inputText value="#{patientListControler.newPatient.name}"
						maxlength="15" required="true"
						rendered="#{patientListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Name']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Gender']}" />
					<p:selectOneMenu id="genderCombo"
						value="#{patientListControler.newPatient.gender}"
						style="width:100%" editable="false">
						<f:selectItems value="#{genderListControler.genderList}"
							var="gender" itemLabel="#{gender.label}"
							itemValue="#{gender.value}" />
					</p:selectOneMenu>
					<h:outputText value="#{dictionaryControler.dictionary['Birthday']}" />
					<p:calendar value="#{patientListControler.newPatient.birthDate}"
						pattern="yyyy-MM-dd" mask="true"
						required="#{patientListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Birthday']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText
						value="#{dictionaryControler.dictionary['PhoneNumber']}" />
					<p:inputText value="#{patientListControler.newPatient.phoneNumber}"
						maxlength="15" required="true"
						rendered="#{patientListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['PhoneNumber']} #{dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="addBtn"
						value="#{dictionaryControler.dictionary['Add']}" ajax="true"
						style="margin-right:5px"
						oncomplete="PF('widgetVar_w').clearFilters();"
						actionListener="#{patientListControler.addNewPatient}"
						update="detailDialog,:form01:patientTable" />
					<p:commandButton id="cancelBtn"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						actionListener="#{patientListControler.cancelAddPatient}"
						immediate="true" update="detailDialog" />
				</div>
				<p:messages showDetail="false" />
			</p:dialog>
			<p:dialog id="detailDialog_1" widgetVar="detailDialog_e"
				resizable="false" draggable="true" closable="false"
				visible="#{patientListControler.editMode}" modal="true"
				header="#{dictionaryControler.dictionary['Edit']} #{dictionaryControler.dictionary['Patient']}"
				style="text-align:center">
				<p:panelGrid columns="2">
					<h:outputText value="#{dictionaryControler.dictionary['Seq']}" />
					<h:outputText value="#{patientListControler.selectedPatient.seq}" />
					<h:outputText value="#{dictionaryControler.dictionary['Name']}" />
					<p:inputText value="#{patientListControler.selectedPatient.name}"
						maxlength="15" required="true"
						rendered="#{patientListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Name']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Gender']}" />
					<p:selectOneMenu id="genderCombo_1"
						value="#{patientListControler.selectedPatient.gender}"
						style="width:100%">
						<f:selectItems value="#{genderListControler.genderList}"
							var="gender"
							itemLabel="#{dictionaryControler.dictionary[gender.label]}"
							itemValue="#{gender.value}" />
					</p:selectOneMenu>
					<h:outputText value="#{dictionaryControler.dictionary['Birthday']}" />
					<p:calendar
						value="#{patientListControler.selectedPatient.birthDate}"
						pattern="yyyy-MM-dd" mask="true"
						required="#{patientListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Birthday']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText
						value="#{dictionaryControler.dictionary['PhoneNumber']}" />
					<p:inputText
						value="#{patientListControler.selectedPatient.phoneNumber}"
						maxlength="15" required="true"
						rendered="#{patientListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['PhoneNumber']} #{dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="saveBtn_1"
						value="#{dictionaryControler.dictionary['Save']}" ajax="true"
						style="margin-right:5px"
						action="#{patientListControler.saveEditPatient}"
						update=":form01:patientTable,detailDialog_1" />
					<p:commandButton id="cancelBtn_1"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						action="#{patientListControler.cancelEditPatient}"
						immediate="true" update="detailDialog_1" />
				</div>
				<p:messages />
			</p:dialog>

			<p:dialog id="registerDialog_id"
				header="#{dictionaryControler.dictionary['Patient']} #{dictionaryControler.dictionary['Register']}"
				widgetVar="registerDialog" showEffect="fade"
				visible="#{registerControler.patientRegisterMode}" hideEffect="fade"
				resizable="false" draggable="true" closable="false" modal="true"
				style="text-align:center">
				<p:panelGrid columns="2" style="margin-bottom:20px;width:350px">
					<h:outputText
						value="#{dictionaryControler.dictionary['Patient']} #{dictionaryControler.dictionary['Seq']}" />
					<h:outputText value="#{registerControler.selectedPatient.seq}" />
					<h:outputText
						value="#{dictionaryControler.dictionary['Patient']} #{dictionaryControler.dictionary['Name']}" />
					<h:outputText value="#{registerControler.selectedPatient.name}" />
					<h:outputText
						value="#{dictionaryControler.dictionary['Department']}" />
					<p:selectOneMenu id="selOneDepartment" style="width:90%"
						value="#{registerControler.selectedDepartmentForPatient}">
						<f:selectItem itemLabel="Select One" itemValue="#{-1}"
							noSelectionOption="true" />
						<f:selectItems value="#{registerControler.onlineDepartments}"
							var="department" itemLabel="#{department.name}"
							itemValue="#{department.seq}" />
						<p:ajax
							listener="#{registerControler.onSelectDepartmentForPatient}"
							update="doctorList,selOneDoctor" />
					</p:selectOneMenu>
					<h:outputText value="#{dictionaryControler.dictionary['Doctor']}" />
					<p:selectOneMenu id="selOneDoctor" style="width:90%"
						value="#{registerControler.selectedDoctorForPatient}">
						<f:selectItem itemLabel="Select One" itemValue="#{-1}"
							noSelectionOption="true" />
						<f:selectItems
							value="#{registerControler.onlineDoctorsForPatient}" var="doctor"
							itemLabel="#{doctor.name}" itemValue="#{doctor.seq}" />
					</p:selectOneMenu>
				</p:panelGrid>
				<p:dataTable id="doctorList" var="doctor" resizableColumns="true"
					style="margin-bottom:20px;width:350px"
					update="registerDialog_id,:form01:messages"
					value="#{registerControler.onlineDoctorsForPatient}">
					<p:column headerText="#{dictionaryControler.dictionary['Doctor']} #{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{doctor.name}" />
					</p:column>
					<p:column
						headerText="#{dictionaryControler.dictionary['Waiting Size']}">
						<h:outputText value="#{doctor.queueSize}" />
					</p:column>
				</p:dataTable>
				<p:messages />
				<div style="text-align: right">
					<p:commandButton
						value="#{dictionaryControler.dictionary['Register']}" ajax="true"
						actionListener="#{registerControler.register}"
						update="registerDialog_id,:form01:messages" style="margin-top:5px" />
					<p:commandButton
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						action="#{registerControler.cancelRegister}" immediate="true"
						update="registerDialog_id" />
				</div>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
</html>